home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / MM3Tp.sea Folder / Made by Marksman / Sources / mm / mmMD_About_Demo.p < prev    next >
Text File  |  1994-01-16  |  10KB  |  286 lines

  1.  
  2. Unit mmMD_About_Demo;
  3. {  mmMD_About_Demo                                 Handle this dialog }
  4. {  Copyright © 1994 George R. Cossey }
  5.  
  6. {    File name:  mmMD_About_Demo
  7.     Function:  Handle this modeless dialog.
  8.  
  9.     This dialog is called when:
  10.  
  11.     History: 1/16/94 Original by George Cossey
  12.  
  13. }
  14.  
  15. { ======================================================= }
  16. { ======================================================= }
  17.  
  18. interface
  19.  
  20.     uses
  21.         Printing,Folders,Sound,mmCommonMM_Demo,CommonMM_Demo,
  22.         mmPA_My_Alert,
  23.         {}
  24.         mmD_My_Modal,
  25.         {}
  26.         UAbout_Demo;
  27.  
  28.  
  29. procedure Init_About_Demo;
  30. procedure Moved_About_Demo(OldRect:Rect;theWindow:WindowPtr);    { Moved this window }
  31. procedure Update_About_Demo(theWindow:WindowPtr);
  32. procedure Open_About_Demo;
  33. procedure Close_About_Demo(theWindow:WindowPtr);
  34. procedure Do_About_Demo(var theEvent:EventRecord;theWindow:WindowPtr;itemHit:integer);
  35.  
  36. { ======================================================= }
  37. { ======================================================= }
  38.  
  39. implementation
  40.  
  41. { ======================================================= }
  42. { ======================================================= }
  43.  
  44. { Routine: Init_About_Demo }
  45. { Purpose: This procedures purpose is to set the window pointer to nil, }
  46. { this is used to tell the other routines }
  47.  
  48. procedure Init_About_Demo;
  49. var
  50.     tempRect:Rect;                                    { Temporary rectangle }
  51.     DType:integer;                                    { Type of dialog item }
  52.     Index:integer;                                    { For looping }
  53.     DItem:Handle;                                    { Handle to the dialog item }
  54.     CItem, CTempItem:ControlHandle;                    { Control handle }
  55.     sTemp:Str255;                                    { Get text entered, temp holding }
  56.     itemHit:integer;                                { Get selection }
  57.     temp:integer;                                    { Get selection, temp holding }
  58.  
  59.  
  60. begin
  61. Rec_About_Demo.theDialog := nil;                    { Initialize to say that the dialog is not yet active }
  62.  
  63. Rec_About_Demo.Enable_OK := true;            { Button }
  64.  
  65. U_Init_About_Demo;                            { Call the user init routine }
  66. end;
  67.  
  68. { ======================================================= }
  69.  
  70. { Routine: Moved_About_Demo }
  71. { Purpose: We were moved, possibly to another screen and screen depth }
  72.  
  73. procedure Moved_About_Demo(OldRect:Rect;theWindow:WindowPtr);    { Moved this window }
  74. var
  75.     SavePort:WindowPtr;                                { Place to save the last port }
  76.  
  77.  
  78. begin
  79. if (Rec_About_Demo.theDialog = theWindow)    then            { Only do if the window is us }
  80.     begin
  81.     GetPort(SavePort);                            { Save the current port }
  82.     SetPort(theWindow);                            { Set the port to my window }
  83.  
  84.     U_Moved_About_Demo(theWindow,OldRect);    { Call user routine when we are moved }
  85.     SetPort(SavePort);                                { Restore the old port }
  86.     end;                                            { End of IF }
  87. end;
  88.  
  89. { ======================================================= }
  90.  
  91. { Routine: Update_About_Demo }
  92. { Purpose: This procedures purpose is to refresh this window, update it, }
  93. { when we are uncovered by another window.  }
  94.  
  95. procedure Update_About_Demo(theWindow:WindowPtr);
  96. var
  97.     SavedPort:GrafPtr;                                { Save the current port so we can restore to it }
  98.     tempRect:Rect;                                    { Temporary rectangle variable }
  99.     rTempRect:Rect;                                    { Temporary rectangle variable }
  100.     DType:integer;                                    { Type of dialog item }
  101.     DItem:Handle;                                    { Handle to the dialog item }
  102.     CItem:ControlHandle;                            { Control handle }
  103.     Saved_ForeColor:RGBColor;                        { Place to save colors }
  104.     Saved_BackColor:RGBColor;                        { Place to save colors }
  105.     DrawingColor:RGBColor;                            { Place to make colors }
  106.  
  107.  
  108. begin
  109. if ((Rec_About_Demo.theDialog <> nil) and (theWindow = Rec_About_Demo.theDialog)) then{ Only do if we are the window to update }
  110.     begin
  111.     GetPort(SavedPort);                            { Get the current port }
  112.     SetPort(theWindow);                            { Point to our port for drawing in our window }
  113.     if (Has.ColorQD) then                                { See if color QuickDraw is around }
  114.         begin
  115.         GetForeColor(Saved_ForeColor);            { Save the fore color }
  116.         GetBackColor(Saved_BackColor);            { Save the back color }
  117.  
  118.         RGBForeColor(Black_ForeColor);            { Set the fore color to Black }
  119.         RGBBackColor(White_BackColor);            { Set the back color to White }
  120.         end;                                        { End of IF }
  121.  
  122.     { This is the default selection, when RETURN is pressed. }
  123.     HiliteDefaultButton(theWindow,ResD_OK);
  124.  
  125.     { Draw static text, Static Text }
  126.     DrawStaticLine(sResD_Static_Text2,30,50,12,systemFont,[]);
  127.  
  128.     { Draw static text, Static Text }
  129.     DrawStaticLine(sResD_Static_Text,45,25,12,systemFont,[]);
  130.  
  131.     TextSize(12);
  132.     TextFont(systemFont);                                { Select the Font that we want }
  133.     TextFace([]);                                        { Select the style that we want }
  134.  
  135.     if (Has.ColorQD) then                                { See if color QuickDraw is around }
  136.         begin
  137.         RGBForeColor(Saved_ForeColor);            { Restore the fore color }
  138.         RGBBackColor(Saved_BackColor);            { Restore the back color }
  139.         end;
  140.  
  141.     U_Update_About_Demo(theWindow);            { Call the user update routine }
  142.  
  143.     DrawDialog(theWindow);                            { Draw the rest of the controls }
  144.     SetPort(SavedPort);                            { Restore the port that we saved at the start }
  145.     end;
  146. end;
  147.  
  148. { ======================================================= }
  149.  
  150. { Routine: Open_About_Demo }
  151. { Purpose: This procedures purpose is to open this window and set all }
  152. { of the initial conditions, such as default edit text. }
  153.  
  154. procedure Open_About_Demo;
  155. var
  156.     ThisEditText:TEHandle; 
  157.     TheDialogPtr:DialogPeek;
  158.     tempRect:Rect;                                { Temporary rectangle variable }
  159.     DType:integer;                                { Type of dialog item }
  160.     DItem:Handle;                                { Handle to the dialog item }
  161.     CItem:ControlHandle;                        { Control handle }
  162.     LTemp,LTemp2,theLong:longint;                { Get selection, temp holding }
  163.  
  164.  
  165. begin
  166. if (Rec_About_Demo.theDialog = NIL) then
  167.     begin
  168.     Rec_About_Demo.theDialog := GetNewDialog(ResD_About_Demo,NIL,WindowPtr(-1));{ Bring in the dialog resource }
  169.     SetPort(Rec_About_Demo.theDialog);        { Prepare to add conditional text }
  170.  
  171.     tempRect := Rec_About_Demo.theDialog^.portRect;            { Get the windows position and size }
  172.     tempRect.left := ((screenBits.bounds.right - screenBits.bounds.left) - (tempRect.right - tempRect.left)) div 2;    { Center Horz }
  173.     tempRect.top := ((screenBits.bounds.bottom - screenBits.bounds.top) - (tempRect.bottom - tempRect.top)) div 3;    { 1/3 vert }
  174.     if (tempRect.top < 40) then                        { Keep below the menu bar }
  175.         tempRect.top := 40;
  176.     MoveWindow(Rec_About_Demo.theDialog,tempRect.left,tempRect.top,true);
  177.  
  178.  
  179.     Doing_MovableModal := true;
  180.     
  181.     { Button }
  182.     SetupNormalControl(Rec_About_Demo.theDialog,ResD_OK,Rec_About_Demo.Enable_OK,0);
  183.  
  184.  
  185.  
  186.     U_Setup_About_Demo(Rec_About_Demo.theDialog);{ Call the user Open procedure }
  187.  
  188.     ShowWindow(Rec_About_Demo.theDialog);                { Open a dialog box }
  189.     SelectWindow(Rec_About_Demo.theDialog);            { Lets see it }
  190.     end
  191. else
  192.     SelectWindow(Rec_About_Demo.theDialog);        { Lets see it }
  193. end;
  194.  
  195. { ======================================================= }
  196.  
  197. { Routine: Close_About_Demo }
  198. { Purpose: This procedures purpose is to close this window and clear }
  199. { the window pointer variable }
  200.  
  201. procedure Close_About_Demo(theWindow:WindowPtr);
  202. var
  203.     tempRect:Rect;                                    { Temporary rectangle }
  204.     DType:integer;                                    { Type of dialog item }
  205.     DItem:Handle;                                    { Handle to the dialog item }
  206.  
  207.  
  208. begin
  209. if ((Rec_About_Demo.theDialog <> NIL) and (theWindow = Rec_About_Demo.theDialog)) then{ Only close if it is us and we were open }
  210.     begin
  211.     U_Close_About_Demo(theWindow);            { Call the user close routine }
  212.  
  213.  
  214.     Doing_MovableModal := false;
  215.     
  216.     DisposDialog(theWindow);                        { Close on the screen and Flush the dialog out of memory }
  217.     Rec_About_Demo.theDialog := nil;            { Make sure our other routines know that we are closed }
  218.     end;
  219. end;
  220.  
  221. { ======================================================= }
  222.  
  223. { Routine: Do_About_Demo }
  224. { Purpose: This procedures purpose is to handle all actions, such as buttons being pressed. }
  225. { This is the real meat of this unit and is where the code is for acting upon the users actions. }
  226.  
  227. procedure Do_About_Demo(var theEvent:EventRecord;theWindow:WindowPtr;itemHit:integer);
  228. var
  229.     Index:integer;                                        { For looping }
  230.     myPt:Point;                                            { For the local mouse position }
  231.     DType:integer;                                        { Type of dialog item }
  232.     DItem:Handle;                                        { Handle to the dialog item }
  233.     tempRect:Rect;                                        { Temporary rectangle }
  234.     CItem:ControlHandle;                                { Control handle }
  235.     temp:integer;                                        { temp integer }
  236.     code:integer;                                        { temp integer }
  237.     theSelection:integer;                                { For Palettes }
  238.     DoubleClick:Boolean;                                { For sensing double clicks in a list }
  239.  
  240.  
  241. begin
  242. Rec_About_Demo.ExitDialog := false;            { Do not close the dialog yet }
  243. if ((theEvent.what = mouseDown) and (Rec_About_Demo.theDialog <> nil)) then
  244.     begin
  245.     SetPort(Rec_About_Demo.theDialog);                    { Set the port to our dialog }
  246.     myPt := theEvent.where;                            { Get the position where the mouse was pressed }
  247.     GlobalToLocal(myPt);                            { Change from global to local location }
  248.  
  249.     end;
  250.  
  251. if ((Rec_About_Demo.theDialog <> nil) and (Rec_About_Demo.theDialog = theWindow)) then
  252.     begin
  253.     CheckKeysInDialog(theWindow,DoubleClick,theEvent,itemHit);
  254.  
  255.     myPt := theEvent.where;                            { Get the position where the mouse was pressed }
  256.     GlobalToLocal(myPt);                            { Change from global to local location }
  257.  
  258.     U_Hit_About_Demo(theWindow,itemHit,Rec_About_Demo.ExitDialog,theEvent);{ Give the user the itemhit }
  259.  
  260.     if (itemHit > 0) then                                { Skip if user set to zero }
  261.         begin
  262.         GetDItem(theWindow,itemHit,DType,DItem,tempRect);{ Get which item was pressed }
  263.         CItem := ControlHandle(DItem);                { Change the pointer for getting to the control }
  264.         end;
  265.     
  266.     { Handle it real time }
  267.     if (itemHit = ResD_OK) then                { Handle the Button being pressed }
  268.         begin
  269.         Add_UserEvent(UserEvent_Close_Window,ResD_About_Demo,0,0,nil);    { Close this modeless dialog }
  270.         Rec_About_Demo.ExitDialog := true;        { Close this dialog, exit }
  271.         end;
  272.  
  273.  
  274.     end;
  275.  
  276. if (Rec_About_Demo.ExitDialog) then                { Do the close of the dialog }
  277.     begin
  278.     Close_About_Demo(Rec_About_Demo.theDialog);
  279.     Rec_About_Demo.theDialog := nil;                    { Clear it for future checks }
  280.     end;
  281. end;
  282.  
  283. { ======================================================= }
  284. { ======================================================= }
  285. end.
  286.